

/* function findSubstr(source, pattern) {
  for (let i = 0; i < source.length; i++) {
    for (let j = 0; j < pattern.length; j++) {
      if (pattern[j] !== source[i + j]) {
        break
      }
      if (j === pattern.length - 1) {
        return i
      }
    }
  }
  return -1
} */



/* //给循环语句label
function findSubstr(source, pattern) {
  outer: for (let i = 0; i < source.length; i++) {
    inner: for (let j = 0; j < pattern.length; j++) {
      if (pattern[j] !== source[i + j]) {
        // break inner
        continue outer
      }
      // if (j === pattern.length - 1) {
      //   return i
      // }
    }
    return i
  }
  return -1
} */
function findSubstr(source, pattern) {
  for (let i = 0; i < source.length; i++) {
    let result = true
    for (let j = 0; j < pattern.length; j++) {
      if (pattern[j] !== source[i + j]) {
        result = false
        break
      }
    }
    if (result) return i
  }
  return -1
}

module.exports = findSubstr
